<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use App\Models\Book;
use Illuminate\Support\Facades\File;
use GuzzleHttp\Client;
use Asymptix\HtmlDomParser\HtmlDomParser;
use App\Models\Operation;
use App\Models\Section;
use App\Jobs\updateBookSectionsFromShuqiba;

class UpdateSectionsFromShuqiba extends Command {
	
	protected $signature = 'shuqiba-update';
	protected $description = 'update shuqiba books';
	
	public function __construct() {
		parent::__construct ();
	}
	
	public function handle() {
		$this->warn('从书旗吧更新已有小说的章节!');
		$books = Book::select(['id', 'name', 'thumbnail', 'abstract', 'author'])
				->where('source' ,Book::SHUQIBA)
				->get();
		$cb = count($books);
		$i = 1;
		foreach($books as $book) {
			dispatch(new updateBookSectionsFromShuqiba($book->href, $book));
			unset($href);
		}
		$this->error('循环结束!');
	}
}